package io.renren.modules.oa.service.impl;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.google.common.collect.Maps;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.datasources.DataSourceNames;
import io.renren.datasources.annotation.DataSource;
import io.renren.modules.oa.dao.OaPlanLogDao;
import io.renren.modules.oa.entity.OaPlanLogEntity;
import io.renren.modules.oa.service.OaPlanLogService;
import io.renren.modules.sys.entity.SysConfigEntity;


@Service("oaPlanLogService")
public class OaPlanLogServiceImpl extends ServiceImpl<OaPlanLogDao, OaPlanLogEntity> implements OaPlanLogService {
	//@DataSource(name = DataSourceNames.SECOND)
    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        Page<OaPlanLogEntity> page = this.selectPage(
                new Query<OaPlanLogEntity>(params).getPage(),
                new EntityWrapper<OaPlanLogEntity>()
                .orderBy("createTime", false)
        );

        return new PageUtils(page);
    }

	@Override
	public OaPlanLogEntity selectByUserid(String userid,String type, Date startTime, Date entTime) {
		return this.selectOne(new EntityWrapper<OaPlanLogEntity>()
				.eq("type", type)
				.eq("userid", userid)
				.ge("create_time", startTime)
				.le("create_time", entTime));
	}

	@Override
	public List<OaPlanLogEntity> selectList(String type,Date startTime, Date entTime) {
		return this.selectList(new EntityWrapper<OaPlanLogEntity>()
				.eq("type", type)
				.ge("create_time", startTime)
				.le("create_time", entTime)
				.orderBy("createTime", true));
	}
	
	public boolean delList(String type,Date startTime){
		return this.delete(new EntityWrapper<OaPlanLogEntity>()
				.eq("type", type)
				.ge("create_time", startTime));
	}
	
	public List<OaPlanLogEntity> queryLastZhiBanList(Long merchantId,Integer pageSize){
		return baseMapper.queryLastZhiBanList(merchantId, pageSize);
	}
	


}
